<?php
/**
 * User: xiongjiaxuan
 * Date: 2019/4/11 21:01
 */

namespace app\common\util;


class UtilVideo {

    //获得视频地址
    public static function convertUrl($url)
    {
        $urlArr = pathinfo($url);
        $vids = $urlArr['filename'];
        $responseUrl = "http://vv.video.qq.com/getinfo?vids=$vids&platform=101001&charge=0&otype=json";
        $res = file_get_contents($responseUrl);
        $res = str_replace('QZOutputJson=','',$res);
        $res =  substr($res,0,strlen($res)-1);
        $res = json_decode($res,true);
        $arr = [];
        if($res['dltype'] == 1){
            $urlArr  = $res['vl']['vi'][0]['ul']['ui'];
            $urlData = $urlArr[mt_rand(0,count($urlArr)-1)];
            $urlData = $urlData['url'];
            $fn = $res['vl']['vi'][0]['fn'];
            $fvkey = $res['vl']['vi'][0]['fvkey'];
            $title = $res['vl']['vi'][0]['ti'];
            $arr['title'] = $title;
            $arr['url'] = $urlData.$fn."?vkey=".$fvkey;
        }
        return $arr['url'];
    }

    public static function fetchCover($url)
    {
        $urlArr = pathinfo($url);
        $vids = $urlArr['filename'];
        $cover = "http://vpic.video.qq.com//${vids}_ori_1.jpg";
        return $cover;
    }

}